#include "FI_CIBRepoFixingData.h"
#include <msgcenter/FIMsgProcess.h>
#include <qbkernel/include/qb_base.h>
#include <qbprotocol/include/rdProto.h>
#include <qbprotocol/include/SSFIModel.h>
#include <qbtools/message/MessagePoster.h>

FICIBRepoFixingData::FICIBRepoFixingData()
{
	m_vctOrder = { "FDR001", "FDR007",	"FDR014" };
	clear();
}

void FICIBRepoFixingData::clear()
{
	m_dataList.m_List.clear();
	m_dataList.m_List.push_back(xBaseUnit_c("FDR001", "CMB1FDR001", "", 0.00000, 0.00000));
	m_dataList.m_List.push_back(xBaseUnit_c("FDR007", "CMB1FDR007", "", 0.00000, 0.00000));
	m_dataList.m_List.push_back(xBaseUnit_c("FDR014", "CMB1FDR014", "", 0.00000, 0.00000));
}

const std::vector<std::string>& FICIBRepoFixingData::getOrder()
{
	return m_vctOrder;
}

const xFixingDepoRepoRateList_c& FICIBRepoFixingData::getData()
{
	return m_dataList;
}

void FICIBRepoFixingData::reqData(MessageReceiver* msgRecv)
{
	static bool reqOnce = false;
	if (reqOnce)return;
	reqOnce = true;

	qb::SSRequestMsg msg;
	msg.m_pRequest = nullptr;
	msg.m_FuncID = E_FID_QB_FIXIN_DEPO_REPO_RATE_QUERY;
	MessagePoster poster(&msg, qbmsg::fixedincome::EncodeFunc);
	poster.send(msgRecv);

	PushMsgInfo pmi3(E_FID_QB_FIXIN_DEPO_REPO_RATE_PUSH, "", nullptr);
	msg.m_FuncID = E_FID_QB_FIXIN_DEPO_REPO_RATE_PUSH;
	msgRecv->registPush(pmi3, &msg, qbmsg::fixedincome::EncodeFunc);
}

bool FICIBRepoFixingData::onReceive(int32_t funcId, const qb::SSAckMsg& msg)
{
	if (funcId != E_FID_QB_FIXIN_DEPO_REPO_RATE_QUERY && funcId != E_FID_QB_FIXIN_DEPO_REPO_RATE_PUSH)return false;

	SCOPED_MUTEX(m_lock);
	clear();
	xFixingDepoRepoRateList_c* pdata = (xFixingDepoRepoRateList_c*)msg.m_pRet;
	if (!pdata)return false;

	m_dataList.m_List = pdata->m_List;
	return true;
}
